﻿<%@ WebHandler Language="C#" Class="codeHandler" %>

using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web.SessionState;
using Dos.Common;

using System.Collections.Generic;


public class codeHandler : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {

        #region 设置,用到Dos.Common
        var config = new CaptchaControl();
        //背景是否动态
        config.IsBackgroundDynamic = true;
        //设置是否对验证码图片中的字符进行旋转形变
        config.AllowDistortion = true;
        //设置是否对验证码图片中的字符进行扭曲形变
        config.AllowCharRotation = true;
        //验证码是否动态
        config.IsForegroundDynamic = true;
        config.Height = 30;
        config.Width = 80;
        //验证码过期时间
        config.ExpireTime = 60;  //60秒
        //设置字体
        config.Fonts = new List<CaptchaFontArrayItem>()
            {
               // new CaptchaFontArrayItem(new Font("Broadway",2,FontStyle.Bold)),
                new CaptchaFontArrayItem(new Font("Cooper Black",2,FontStyle.Bold))
            };
        //背景颜色
        config.BackColor = Color.Bisque;
        //验证码保存在Session["ranCode"]中,也可以用CaptchaControl.CaptchaValidate(enterCode)方法验证
        config.SessionName = "ranCode";
        #endregion
        var h = new Captcha();
        h.ProcessRequest();  //生成验证码，并显示

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}